# $Id$
# Maintainer: Florian Pritz <bluewind@xinu.at>
# Contributor: Angel Velasquez <angvp@archlinux.org>
# Contributor: kevin <kevin.archlinux.org>
# Contributor: judd <jvinet.zeroflux.org>
# Contributor: francois <francois.archlinux.org>

pkgname=perl
pkgver=5.26.1
_baseversion="${pkgver%.*}"
pkgrel=1
pkgdesc="A highly capable, feature-rich programming language"
arch=(i686 x86_64)
license=('GPL' 'PerlArtistic')
url="http://www.perl.org"
groups=('base')
depends=('gdbm' 'db' 'glibc')
# NOTE: This array is automatically generated by `./patchprov`.
#       If you want to add entries, do so in the next array.
provides=('perl-archive-tar=2.24'
          'perl-attribute-handlers=0.99'
          'perl-autodie=2.29'
          'perl-autoloader=5.74'
          'perl-autouse=1.11'
          'perl-b-debug=1.24'
          'perl-base=2.26'
          'perl-bignum=0.47'
          'perl-carp=1.42'
          'perl-compress-raw-bzip2=2.074'
          'perl-compress-raw-zlib=2.074'
          'perl-config-perl-v=0.28'
          'perl-constant=1.33'
          'perl-cpan-meta-requirements=2.140'
          'perl-cpan-meta-yaml=0.018'
          'perl-cpan-meta=2.150010'
          'perl-cpan=2.18'
          'perl-data-dumper=2.167'
          'perl-db_file=1.840'
          'perl-devel-ppport=3.35'
          'perl-devel-selfstubber=1.06'
          'perl-digest-md5=2.55'
          'perl-digest-sha=5.96'
          'perl-digest=1.17_01'
          'perl-dumpvalue=1.18'
          'perl-encode=2.88'
          'perl-encoding-warnings=0.13'
          'perl-env=1.04'
          'perl-experimental=0.016'
          'perl-exporter=5.72'
          'perl-extutils-cbuilder=0.280225'
          'perl-extutils-constant=0.23'
          'perl-extutils-install=2.04'
          'perl-extutils-makemaker=7.24'
          'perl-extutils-manifest=1.70'
          'perl-extutils-parsexs=3.34'
          'perl-file-fetch=0.52'
          'perl-file-path=2.12_01'
          'perl-file-temp=0.2304'
          'perl-filter-simple=0.93'
          'perl-filter-util-call=1.55'
          'perl-getopt-long=2.49'
          'perl-http-tiny=0.070'
          'perl-i18n-collate=1.02'
          'perl-i18n-langtags=0.42'
          'perl-if=0.0606'
          'perl-io-compress=2.074'
          'perl-io-socket-ip=0.38'
          'perl-io-zlib=1.10'
          'perl-io=1.38'
          'perl-ipc-cmd=0.96'
          'perl-ipc-sysv=2.07'
          'perl-json-pp=2.27400_02'
          'perl-lib=0.64'
          'perl-libnet=3.10'
          'perl-locale-codes=3.42'
          'perl-locale-maketext-simple=0.21_01'
          'perl-locale-maketext=1.28'
          'perl-math-bigint-fastcalc=0.5005'
          'perl-math-bigint=1.999806'
          'perl-math-bigrat=0.2611'
          'perl-math-complex=1.5901'
          'perl-memoize=1.03_01'
          'perl-mime-base64=3.15'
          'perl-module-corelist=5.20170922_26'
          'perl-module-load-conditional=0.68'
          'perl-module-load=0.32'
          'perl-module-loaded=0.08'
          'perl-module-metadata=1.000033'
          'perl-net-ping=2.55'
          'perl-params-check=0.38'
          'perl-parent=0.236'
          'perl-pathtools=3.67'
          'perl-perl-ostype=1.010'
          'perl-perlfaq=5.021011'
          'perl-perlio-via-quotedprint=0.08'
          'perl-pod-checker=1.73'
          'perl-pod-escapes=1.07'
          'perl-pod-parser=1.63'
          'perl-pod-perldoc=3.28'
          'perl-pod-simple=3.35'
          'perl-pod-usage=1.69'
          'perl-podlators=5.006'
          'perl-safe=2.40'
          'perl-scalar-list-utils=1.46_02'
          'perl-search-dict=1.07'
          'perl-selfloader=1.23'
          'perl-socket=2.020_03'
          'perl-storable=2.62'
          'perl-sys-syslog=0.35'
          'perl-term-ansicolor=4.06'
          'perl-term-cap=1.17'
          'perl-term-complete=1.403'
          'perl-term-readline=1.16'
          'perl-test-harness=3.38'
          'perl-test-simple=1.302073'
          'perl-test=1.30'
          'perl-text-abbrev=1.02'
          'perl-text-balanced=2.03'
          'perl-text-parsewords=3.30'
          'perl-text-tabs=2013.0523'
          'perl-thread-queue=3.12'
          'perl-thread-semaphore=2.13'
          'perl-threads-shared=1.56'
          'perl-threads=2.15'
          'perl-tie-file=1.02'
          'perl-tie-refhash=1.39'
          'perl-time-hires=1.9741'
          'perl-time-local=1.25'
          'perl-time-piece=1.31'
          'perl-unicode-collate=1.19'
          'perl-unicode-normalize=1.25'
          'perl-version=0.9917'
          'perl-xsloader=0.27')
# Add your own provides here
provides=(${provides[@]})
source=(https://www.cpan.org/src/5.0/perl-${pkgver}.tar.xz
        perlbin.sh
        perlbin.csh
        perlbin.fish
        perl-binary-module-dependency-1.template
        detect-old-perl-modules.sh
        detect-old-perl-modules.hook)
options=('makeflags' '!purge' 'emptydirs')
md5sums=('70e988b4318739b0cf3ad5e120bfde88'
         'f2a1ee55a05e84652cb10cab17a4c546'
         'd8153ad4a43bb4142d1bdeaa9fcdd95b'
         '626605dc8beef956cbaf46f031c7e894'
         '2a366dfc783c460764cde0caf88a23af'
         '2fa12aa0f924e8dccb4dab84ca3e0db3'
         '80bc41c440de5fd36fb5bb199ad2a314')
sha256sums=('fe8208133e73e47afc3251c08d2c21c5a60160165a8ab8b669c43a420e4ec680'
            '7469f4b645e5f7460b76bcdf44268823600e99c10be5765c451f55b43e14664f'
            '478a52dc440d5ca324f4c95238b39cc8c90d5d7d8d5601fa085ffef79fea04f4'
            '11ce66bcf4803b0bf27179a32ce53f41bcdfa967c4c0d54ac103dbc4951d18a3'
            '6750ef8a0458d3377ad13f863d2eab09084932ee58de1abd92ed1e702bb93e3e'
            'c5db3dcd1db71724fa4df5db34586688aa8db92ac6ffcbddaaa213c71cceff20'
            'b310d418db6e301cf07a6093c187a629dfc61db093bc08533d74bfc89d8a759c')
# https://www.cpan.org/src/5.0/perl-$pkgver.tar.xz.sha256.txt

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}

}

build() {
  cd ${srcdir}/${pkgname}-${pkgver}

  if [ "${CARCH}" = "x86_64" ]; then
    # for x86_64
    arch_opts="-Dcccdlflags='-fPIC'"
  else
    # for i686
    arch_opts=""
  fi

  ./Configure -des -Dusethreads -Duseshrplib -Doptimize="${CFLAGS}" \
    -Dprefix=/usr -Dvendorprefix=/usr \
    -Dprivlib=/usr/share/perl5/core_perl \
    -Darchlib=/usr/lib/perl5/$_baseversion/core_perl \
    -Dsitelib=/usr/share/perl5/site_perl \
    -Dsitearch=/usr/lib/perl5/$_baseversion/site_perl \
    -Dvendorlib=/usr/share/perl5/vendor_perl \
    -Dvendorarch=/usr/lib/perl5/$_baseversion/vendor_perl \
    -Dscriptdir=/usr/bin/core_perl \
    -Dsitescript=/usr/bin/site_perl \
    -Dvendorscript=/usr/bin/vendor_perl \
    -Dinc_version_list=none \
    -Dman1ext=1perl -Dman3ext=3perl ${arch_opts} \
    -Dlddlflags="-shared ${LDFLAGS}" -Dldflags="${LDFLAGS}"
  make
}

check() {
  cd ${srcdir}/${pkgname}-${pkgver}
  TEST_JOBS=$(echo $MAKEFLAGS | sed 's/.*-j\([0-9][0-9]*\).*/\1/') make test_harness
#  make test
}

package() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make DESTDIR="$pkgdir" install

  for template in "$srcdir/"*.template; do
    install -Dm644 "$template" "$pkgdir/usr/share/makepkg-template/${template##*/}"
  done
  ln -s perl-binary-module-dependency-1.template "$pkgdir/usr/share/makepkg-template/"perl-binary-module-dependency.template

  ### Perl Settings ###
  # Change man page extensions for site and vendor module builds.
  # Set no mail address since bug reports should go to the bug tracker
  # and not someone's email.
  sed -e '/^man1ext=/ s/1perl/1p/' -e '/^man3ext=/ s/3perl/3pm/' \
      -e "/^cf_email=/ s/'.*'/''/" \
      -e "/^perladmin=/ s/'.*'/''/" \
      -i ${pkgdir}/usr/lib/perl5/$_baseversion/core_perl/Config_heavy.pl

  ### CPAN Settings ###
  # Set CPAN default config to use the site directories.
  sed -e '/(makepl_arg =>/   s/""/"INSTALLDIRS=site"/' \
      -e '/(mbuildpl_arg =>/ s/""/"installdirs=site"/' \
      -i ${pkgdir}/usr/share/perl5/core_perl/CPAN/FirstTime.pm

  # Profile script to set paths to perl scripts.
  install -D -m755 ${srcdir}/perlbin.sh \
                   ${pkgdir}/etc/profile.d/perlbin.sh
  # Profile script to set paths to perl scripts on csh. (FS#22441)
  install -D -m755 ${srcdir}/perlbin.csh \
                  ${pkgdir}/etc/profile.d/perlbin.csh
  # Profile script to set paths to perl scripts on fish. (FS#51191)
  install -D -m 755 "$srcdir/perlbin.fish" \
                  "$pkgdir/usr/share/fish/vendor_conf.d/perlbin.fish"

  # Add the dirs so new installs will already have them in PATH once they
  # install their first perl programm
  install -d -m755 "$pkgdir/usr/bin/vendor_perl"
  install -d -m755 "$pkgdir/usr/bin/site_perl"

  #(cd ${pkgdir}/usr/bin; mv perl${pkgver} perl)
  rm "$pkgdir/usr/bin/perl$pkgver"

  install -D -m755 -t "$pkgdir/usr/share/libalpm/scripts" "$srcdir/detect-old-perl-modules.sh"
  install -D -m644 -t "$pkgdir/usr/share/libalpm/hooks" "$srcdir/detect-old-perl-modules.hook"

  find $pkgdir -name perllocal.pod -delete
  find $pkgdir -name .packlist -delete
}
